package com.foton.ai.controller;


import com.foton.ai.service.TongYiService;
import com.foton.ai.service.factory.TongYiStrategyFactory;
import com.foton.ai.service.impl.TongYiAudioSimpleServiceImpl;
import com.foton.ai.service.impl.TongYiImageServiceImpl;
import org.springframework.ai.image.ImageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * ai 控制层
 */
@RestController
@RequestMapping("/ai")
@CrossOrigin
public class TongYiController {
//    @Autowired
//    @Qualifier("tongYiSimpleServiceImpl")
//    private TongYiService tongYiSimpleService;

    @Autowired
    @Qualifier("tongYiImageServiceImpl")
    private TongYiImageServiceImpl tongYiImageServiceImpl;


    @Autowired
    @Qualifier("tongYiAudioSimpleServiceImpl")
    private TongYiAudioSimpleServiceImpl tongYiAudioSimpleServiceImpl;



    @Autowired
    Map<Integer, TongYiService> idGeneratorMap;

    @Value("${spring.application.name}")
    private String applicationName;


    /**
     * 工程测试接口
     * @param message
     * @return
     */
    @GetMapping("/requestTest")
    public String requestTest(
            @RequestParam(value = "message", defaultValue = "AI时代下Java开发者该何去何从？")
            String message
    ) {
        return "welcome to "+applicationName;
    }






    /**
     * 简单模式 - 文件对话
     * @param message
     * @param mode
     * @return
     */
    @GetMapping("/simple")
    public String completion(
            @RequestParam(value = "message", defaultValue = "AI时代下Java开发者该何去何从？")
            String message,@RequestParam(value = "mode",defaultValue = "1")  Integer mode
    ) {
        TongYiService tongYiService = idGeneratorMap.get(mode);
       return tongYiService.completion(message);

        //return tongYiSimpleService.completion(message);
    }


    /**
     * 图文模式 - 根据文本描述返回图片
     * @param message
     * @return
     */
    @GetMapping("/getImage")
    public ImageResponse getImage(
            @RequestParam(value = "message", defaultValue = "AI时代下Java开发者该何去何从？")
            String message
    ) {
        return tongYiImageServiceImpl.genImg(message);
    }


    /**
     *  音频模式 - 根据语音，音频转换为文字
     * @param message
     * @return
     */
    @GetMapping("/getAudio")
    public String getAudio(
            @RequestParam(value = "message", defaultValue = "AI时代下Java开发者该何去何从？")
            String message
    ) {
        return tongYiAudioSimpleServiceImpl.genAudio(message);
    }




}
